package weapon;

import static java.util.stream.Collectors.toSet;

import java.util.Set;

import com.item.manager.Template;

public class Weapon {
    private final String name;
    private final int combat;
    private final Set<WeaponFeature> features;

    public Weapon(Template template) {
        this.name = template.name();
        this.combat = template.findAttr("Combat").asInt();
        this.features = template.findAttrSet("Feature").stream().map(attr -> WeaponFeature.valueOf(attr.asString())).collect(toSet());
    }

    public String getName() {
        return this.name;
    }

    @Override
    public String toString() {
        return this.name;
    }

    public int getCombat() {
        return this.combat;
    }

    public Set<WeaponFeature> getFeatures() {
        return this.features;
    }

    public boolean hasFeature(WeaponFeature feature) {
        return features.contains(feature);
    }
}
